//
//  PurchaseHistoryCell.swift
//  Exam-iOS
//
//  Created by 李胜锋 on 2018/3/23.
//  Copyright © 2018年 李胜锋. All rights reserved.
//

import Foundation
import UIKit
import SnapKit
import Then

class PurchaseHistoryCell: UITableViewCell {
    
    var titleLabel: UILabel!
    var dateLabel: UILabel!
    var rightLabel: UILabel!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setup()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup() {
        separatorInset = UIEdgeInsetsMake(0, 21, 0, 0)
        
        titleLabel = UILabel().then({ (label) in
            label.font = UIFont.systemFont(ofSize: 14)
            label.textAlignment = .left
            label.textColor = UIColor.black
            
            self.contentView.addSubview(label)
            label.snp.makeConstraints({ (maker) in
                maker.leading.equalTo(21)
                maker.top.equalTo(7)
            })
        })
        
        dateLabel = UILabel().then({ (label) in
            label.font = UIFont.systemFont(ofSize: 12)
            label.textAlignment = .left
            label.textColor = UIColor.lsf_color16(0x9B9B9B)
            
            self.contentView.addSubview(label)
            label.snp.makeConstraints({ (maker) in
                maker.leading.equalTo(21)
                maker.top.equalTo(titleLabel.snp.bottom).offset(5)
                maker.bottom.equalTo(-8)
            })
        })
        
        rightLabel = UILabel().then({ (label) in
            label.font = UIFont.systemFont(ofSize: 14)
            label.textAlignment = .right
            label.textColor = UIColor.black
            
            self.contentView.addSubview(label)
            label.snp.makeConstraints({ (maker) in
                maker.trailing.equalTo(-12)
                maker.centerY.equalToSuperview()
            })
        })
    }
    
    public func set(title: String?, date: String?, cost: Int?) {
        titleLabel.text = title
        dateLabel.text = date
        rightLabel.text = "￥\(cost ?? 0)"
    }
}
